<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        
        <title>
            
    
                Horizontal Sharding
             &mdash; 
    SQLAlchemy 0.8 Documentation

        </title>
        
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/docs.css" type="text/css" />

    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
          URL_ROOT:    '../../',
          VERSION:     '0.8.2',
          COLLAPSE_MODINDEX: false,
          FILE_SUFFIX: '.html'
      };
    </script>
        <script type="text/javascript" src="../../_static/jquery.js"></script>
        <script type="text/javascript" src="../../_static/underscore.js"></script>
        <script type="text/javascript" src="../../_static/doctools.js"></script>
    <script type="text/javascript" src="../../_static/init.js"></script>
    <link rel="index" title="Index" href="../../genindex.html" />
    <link rel="search" title="Search" href="../../search.html" />
        <link rel="copyright" title="Copyright" href="../../copyright.html" />
    <link rel="top" title="SQLAlchemy 0.8 Documentation" href="../../index.html" />
        <link rel="up" title="ORM Extensions" href="index.html" />
        <link rel="next" title="Hybrid Attributes" href="hybrid.html" />
        <link rel="prev" title="Ordering List" href="orderinglist.html" />

    </head>
    <body>
        










<div id="docs-container">



<div id="docs-header">
    <h1>SQLAlchemy 0.8 Documentation</h1>

    <div id="docs-search">
    Search:
    <form class="search" action="../../search.html" method="get">
      <input type="text" name="q" size="18" /> <input type="submit" value="Search" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    </div>

    <div id="docs-version-header">
        Release: <span class="version-num">0.8.2</span> | Release Date: July 3, 2013


    </div>

</div>

<div id="docs-top-navigation">
    <div id="docs-top-page-control" class="docs-navigation-links">
        <ul>
            <li>Prev:
            <a href="orderinglist.html" title="previous chapter">Ordering List</a>
            </li>
            <li>Next:
            <a href="hybrid.html" title="next chapter">Hybrid Attributes</a>
            </li>

        <li>
            <a href="../../contents.html">Table of Contents</a> |
            <a href="../../genindex.html">Index</a>
            | <a href="../../_sources/orm/extensions/horizontal_shard.txt">view source
        </li>
        </ul>
    </div>

    <div id="docs-navigation-banner">
        <a href="../../index.html">SQLAlchemy 0.8 Documentation</a>
                » <a href="../index.html" title="SQLAlchemy ORM">SQLAlchemy ORM</a>
                » <a href="index.html" title="ORM Extensions">ORM Extensions</a>
        » 
                Horizontal Sharding
             

        <h2>
            
                Horizontal Sharding
            
        </h2>
    </div>

</div>

<div id="docs-body-container">

    <div id="docs-sidebar">
    <h3><a href="../../index.html">Table of Contents</a></h3>
    <ul>
<li><a class="reference internal" href="#">Horizontal Sharding</a><ul>
<li><a class="reference internal" href="#api-documentation">API Documentation</a></li>
</ul>
</li>
</ul>


    <h4>Previous Topic</h4>
    <p>
    <a href="orderinglist.html" title="previous chapter">Ordering List</a>
    </p>
    <h4>Next Topic</h4>
    <p>
    <a href="hybrid.html" title="next chapter">Hybrid Attributes</a>
    </p>


    <h4>Quick Search</h4>
    <p>
    <form class="search" action="../../search.html" method="get">
      <input type="text" name="q" size="18" /> <input type="submit" value="Search" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    </p>

    </div>

    <div id="docs-body" class="withsidebar" >
        
<div class="section" id="module-sqlalchemy.ext.horizontal_shard">
<span id="horizontal-sharding"></span><h1>Horizontal Sharding<a class="headerlink" href="#module-sqlalchemy.ext.horizontal_shard" title="Permalink to this headline">¶</a></h1>
<p>Horizontal sharding support.</p>
<p>Defines a rudimental &#8216;horizontal sharding&#8217; system which allows a Session to
distribute queries and persistence operations across multiple databases.</p>
<p>For a usage example, see the <a class="reference internal" href="../examples.html#examples-sharding"><em>Horizontal Sharding</em></a> example included in
the source distribution.</p>
<div class="section" id="api-documentation">
<h2>API Documentation<a class="headerlink" href="#api-documentation" title="Permalink to this headline">¶</a></h2>
<dl class="class">
<dt id="sqlalchemy.ext.horizontal_shard.ShardedSession">
<em class="property">class </em><tt class="descclassname">sqlalchemy.ext.horizontal_shard.</tt><tt class="descname">ShardedSession</tt><big>(</big><em>shard_chooser</em>, <em>id_chooser</em>, <em>query_chooser</em>, <em>shards=None</em>, <em>query_cls=&lt;class 'sqlalchemy.ext.horizontal_shard.ShardedQuery'&gt;</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#sqlalchemy.ext.horizontal_shard.ShardedSession" title="Permalink to this definition">¶</a></dt>
<dd><dl class="method">
<dt id="sqlalchemy.ext.horizontal_shard.ShardedSession.__init__">
<tt class="descname">__init__</tt><big>(</big><em>shard_chooser</em>, <em>id_chooser</em>, <em>query_chooser</em>, <em>shards=None</em>, <em>query_cls=&lt;class 'sqlalchemy.ext.horizontal_shard.ShardedQuery'&gt;</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#sqlalchemy.ext.horizontal_shard.ShardedSession.__init__" title="Permalink to this definition">¶</a></dt>
<dd><p>Construct a ShardedSession.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>shard_chooser</strong> &#8211; A callable which, passed a Mapper, a mapped
instance, and possibly a SQL clause, returns a shard ID.  This id
may be based off of the attributes present within the object, or on
some round-robin scheme. If the scheme is based on a selection, it
should set whatever state on the instance to mark it in the future as
participating in that shard.</li>
<li><strong>id_chooser</strong> &#8211; A callable, passed a query and a tuple of identity
values, which should return a list of shard ids where the ID might
reside.  The databases will be queried in the order of this listing.</li>
<li><strong>query_chooser</strong> &#8211; For a given Query, returns the list of shard_ids
where the query should be issued.  Results from all shards returned
will be combined together into a single listing.</li>
<li><strong>shards</strong> &#8211; A dictionary of string shard names
to <a class="reference internal" href="../../core/connections.html#sqlalchemy.engine.Engine" title="sqlalchemy.engine.Engine"><tt class="xref py py-class docutils literal"><span class="pre">Engine</span></tt></a> objects.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</dd></dl>

<dl class="class">
<dt id="sqlalchemy.ext.horizontal_shard.ShardedQuery">
<em class="property">class </em><tt class="descclassname">sqlalchemy.ext.horizontal_shard.</tt><tt class="descname">ShardedQuery</tt><big>(</big><em>*args</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#sqlalchemy.ext.horizontal_shard.ShardedQuery" title="Permalink to this definition">¶</a></dt>
<dd><dl class="method">
<dt id="sqlalchemy.ext.horizontal_shard.ShardedQuery.set_shard">
<tt class="descname">set_shard</tt><big>(</big><em>shard_id</em><big>)</big><a class="headerlink" href="#sqlalchemy.ext.horizontal_shard.ShardedQuery.set_shard" title="Permalink to this definition">¶</a></dt>
<dd><p>return a new query, limited to a single shard ID.</p>
<p>all subsequent operations with the returned query will
be against the single shard regardless of other state.</p>
</dd></dl>

</dd></dl>

</div>
</div>

    </div>

</div>

<div id="docs-bottom-navigation" class="docs-navigation-links">
        Previous:
        <a href="orderinglist.html" title="previous chapter">Ordering List</a>
        Next:
        <a href="hybrid.html" title="next chapter">Hybrid Attributes</a>

    <div id="docs-copyright">
        &copy; <a href="../../copyright.html">Copyright</a> 2007-2013, the SQLAlchemy authors and contributors.
        Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3.
    </div>
</div>

</div>

        
    </body>
</html>


